// GreedAR1.mod called by SimGreedModelOnceFinal.m and SimGreedModelLoopFinal.m

var w v theta pi vL vW EvL EvW;    // Endogenous variables: log wage;  log violence; log TFP/commodity prices; log profits; log value if losing; log value if winning; expected log  value if losing; expected log value if winning
varexo thetashock;                 // Exogenous variables: shock to TFP/commodity prices

parameters 
beta thetabar alpha phi psi  rho vbar vbarW vbarL wbar lambda; 
beta=beta1;                             // Quarterly discount rate (in the manuscript we call this delta, because beta is the coefficient in a regression
thetabar=thetabar1;                     // Steady State TFP level (not logged!) 
alpha=alpha1;                           // Share of labor in production.
phi=phi1;                               // Opportunity cost is -phi
psi=psi1;                               // Scaling factor on the probability of winning the war
rho=rho1;                               // Quarterly persistence of TFP/commodity price shock
vbar=vbar1;                             // Steady state violence 
vbarW=vbarW1;                           // Steady state value LOW (if the rebels are NOT in power)
vbarL=vbarL1;                           // Steady state value HIGH (if the rebels are  in power)
lambda=lambda1;                         // Efficiency cost of government run by the rebels (1 is default)
wbar=alpha*thetabar*(1-vbar)^(alpha-1); // Steady state wages (if rebels are not in power)

model;                                                          // Equation numbers from Appendix 1.3.2
w=theta+(1-alpha)*(vbar/(1-vbar))*v;                            // 1. Wages
v=-phi*w+phi*(vbarW*vW(+1)-vbarL*vL(+1))/(vbarW-vbarL);         // 2. FOC (rearraged with violence on LHS like in regression)
vW=(1-beta)*theta+beta*vW(+1);                                  // 3. Value of winning (rebels are in power)        
vbarL*vL=w*(wbar*(1-vbar))
        -v*vbar*wbar
        +v*((1-1/phi)*psi*vbar^(1-1/phi)*beta*(vbarW-vbarL))   
        +vW(+1)*(beta*psi*vbar^(1-1/phi)*vbarW)
        +vL(+1)*beta*vbarL*(1-psi*vbar^(1-1/phi));              // 4. Value of losing state (rebels are in power)
theta=rho*theta(-1)+thetashock;                                 // Exogenous process for TFP shock
pi=theta-alpha*(vbar/(1-vbar))*v;                               // Memoradum item: Definition of profits today 
EvL=vL(+1);                                                     // Memoradum item: holder for next period expected value of losing
EvW=vW(+1);                                                     // Memoradum item: holder for next period expected value of winning
end;

steady;
check;

shocks;
var thetashock;
stderr 0.01;
end;

stoch_simul(irf=40,order=1, noprint, nograph, periods=1000, drop=100);


